# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models


class AccountChartTemplate(models.Model):
    _inherit = "account.chart.template"

    def _load(self, sale_tax_rate, purchase_tax_rate, company):
        super_ret = super(AccountChartTemplate, self)._load(
            sale_tax_rate, purchase_tax_rate, company)

        # Set the transfer account on the company
        self._set_company_transfer_account(company)

        return super_ret

    def _set_company_transfer_account(self, company):
        # odoo 官方代码, 查找 transfer_account 时, 忽略了 reconcile=True 这个条件, 会取错科目
        company.transfer_account_id = self.env['account.account'].search([
            ('code', '=like', self.transfer_account_code_prefix + '%'),
            ('reconcile', '=', True),
            ('company_id', '=', company.id)], limit=1)
